// pages/home/fahuo/fahuo.js

const {fahuo, kuaidi} =require('../../../util/api')

Page({

  /**
   * 页面的初始数据
   */
  data: {
   
    wuliudanhao:"",
    dictValue: "",
    shebeibianhao:"",
    userId:"",
    orderId:"",
    wuliuId:"",
    heqCode:"",
    wuliu:"",
    kuaidigongsi:false,
    objectArray: [{
      
    }],
     address:{}
  },
  bindPickerChange:function(e) {
    const index = e.detail.value
   this.setData({
     kuaidigongsi:true,
    wuliuId:this.data.objectArray[index].dictValue,
    dictValue:this.data.objectArray[index].dictLabel
    
   })
    console.log(this.data.wuliuId,this.data.dictValue)
  },
  scan(){
  wx.scanCode({
    success: (res)=>  {
      console.log(res.result)
      this.setData({
        wuliudanhao:res.result
      })
    }
  })},

  scan1(){
    wx.scanCode({
      success: (res)=>  {
        console.log(res.result)
        this.setData({
          shebeibianhao:res.result
        })
      }
    })},
  handTap(){

    if (this.data.wuliuId=='' ) {
      wx.showToast({
        title: "请选择物流公司",
        icon: 'error',
        duration: 2000
      })
      return false;
    }
    if (this.data.wuliudanhao=='') {
      wx.showToast({
        title: "请输入快递单号",
        icon: 'error',
        duration: 2000
      })
      return false;
    }
    if (this.data.shebeibianhao=='' ) {
      wx.showToast({
        title: "请输入设备编号",
        icon: 'error',
        duration: 2000
      })
      return false;
    }
    
      let params={
        userId:wx.getStorageSync('userId'),
        orderId:this.data.orderId,
        wuliuid:this.data.wuliuId,
        wuliudanhao:this.data.wuliudanhao,
        heqCode:this.data.shebeibianhao
     }
      wx.showModal({
        title: '提示',
        content: '是否确定发货',
        success (res)  {
          if (res.confirm) {
            console.log('用户点击确定')
            fahuo(params).then(res=>{
              if(res.code == 200)
              {
                wx.showToast({
                  title: "发货成功",
                  icon: 'success',
                  duration: 2000
                })
                wx.navigateBack({
                  delta: 1
                   })
              }else{
                wx.showToast({
                  title: res.msg,
                  icon: 'none',
                  duration: 2000})
              }
              
              //  wx.navigateBack({
              //   delta: 1
              // })
            })
           
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    
   
    },
    inputChange(e){
      this.setData({
        wuliudanhao:e.detail.value
      })

      
    },

    copy()
    {
      let address = this.data.address
      wx.setClipboardData({
          data: address.memberName + " " + address.telNum + " " + address.provinceName + " " + address.cityName + " " + address.countyName + " " + address.detailInfo,
          success: function(res) {
           // self.setData({copyTip:true}),
           wx.showToast({
              title: '复制成功',
              icon:'success'
            })
          }
         });
    },
 
  inputChange1(e){
    
    this.setData({
      shebeibianhao:e.detail.value
    })

  
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
   
   this.setData({
     orderId:options.id,
     address:JSON.parse(options.address)
   })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

    kuaidi().then(res=>{
     
      this.setData({
        objectArray:res.data
        
    })

  },
    )},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})